<?php

use yii\db\Migration;

class m171027_073347_create_class_manage_attribute extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%class_manage_attribute}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'class_id' => $this->integer()->defaultValue(0).' COMMENT \'班级id\'',
                'course_id' => $this->integer()->defaultValue(0).' COMMENT \'课程id\'',
                'course' => $this->string(200)->defaultValue(0).' COMMENT \'课程名称\'',
                'teacher_id' => $this->integer()->defaultValue(0).' COMMENT \'老师id\'',
                'teacher' => $this->string(50)->defaultValue(null).' COMMENT \'老师\'',
                'room_id' => $this->integer()->defaultValue(0).' COMMENT \'教室id\'',
                'classroom_name' => $this->string(50)->defaultValue(null).' COMMENT \'教室\'',
                'classroom_number' => $this->string(50)->defaultValue(null).' COMMENT \'教室编号\'',
                'teacher_form' => $this->smallInteger(2)->defaultValue(0).' COMMENT \'授课方式\'',
                'price' => $this->decimal(10,2)->defaultValue(0).' COMMENT \'价格\'',
                'class_count' => $this->smallInteger()->defaultValue(0).' COMMENT \'课次\'',
                'subsidy' => $this->decimal(10,2)->defaultValue(0).' COMMENT \'课时补贴\'',
                'suitable_age' => $this->string(50)->defaultValue(null).' COMMENT \'年龄段\'',
                'class_length' => $this->smallInteger()->defaultValue(0).' COMMENT \'时长\'',
                'max_number' => $this->smallInteger()->defaultValue(0).' COMMENT \'最满人数\'',
                'opening_number' => $this->smallInteger()->defaultValue(0).' COMMENT \'开班人数\'',
                'is_booking' => $this->smallInteger(1)->defaultValue(0).' COMMENT \'是否可预约\'',
                'is_buy' => $this->smallInteger(1)->defaultValue(0).' COMMENT \'是否可购买\'',
                'region' => $this->string(100)->defaultValue(null).' COMMENT \'区域\'',
                'tutor_id' =>$this->smallInteger()->defaultValue(0)->comment('导师'),
                'deposit' =>$this->decimal()->defaultValue(0)->comment('保证金'),
                'is_group' =>$this->smallInteger(2)->defaultValue(0)->comment('是否组合艺教学 0 否 1是'),
                'discount_type' =>$this->smallInteger(2)->defaultValue(0)->comment('价格优惠类型（1，按比例 2 固定减额）'),
                'reduce' =>$this->smallInteger()->defaultValue(0)->comment('价格减少（比例整数）'),
                'subsidy_type' =>$this->smallInteger(2)->defaultValue(1)->comment('课时补助类型（1，按学生 2 课程）'),
                'commission_rate' =>$this->smallInteger(3)->defaultValue(0)->comment('佣金比例'),
                'is_goods' =>$this->smallInteger(1)->defaultValue(0)->comment('是否生成商品 0 否 1 是'),
                'arrangement_id' =>$this->integer()->defaultValue(0)->comment('排课id'),
                'room_group_id' =>$this->smallInteger()->defaultValue(0)->comment('教室组id'),
                'room_group_name' =>$this->string(50)->defaultValue(null)->comment('教室组名'),
                'room_type' =>$this->smallInteger(2)->defaultValue(0)->comment('教室类型 （0 正常教室，1 共享教室）'),
                'updated_at' =>$this->integer()->defaultValue(0)->comment('修改时间'),
                'created_at'=> $this->integer()->defaultValue(0)->comment('创建时间'),
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%class_manage_attribute}}');
        }
    }

}
